package com.yinhai;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 
 * @author caizh
 * purpose：该servlet用于处理接收相应的请求并分发给相应的功能SERVLET进行处理
 * create date:2010.01.06
 * last update:caizh
 */
public class DispatchRequest extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public DispatchRequest() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		/*备注servlet完整的映射路径为：http://localhost:8080/DeploySYS/servlet/DispatchRequest
		 * 如用sendRedirect("../caizh/FILE/FileMain.jsp")则正确，完整的映射路径为：http://localhost:8080/DeploySYS/caizh/FILE/FileMain.jsp
		 * 如用sendRedirect("./caizh/FILE/FileMain.jsp")则错误，完整的映射路径为：http://localhost:8080/DeploySYS/servlet/caizh/FILE/FileMain.jsp
		 * 说需要跳转，需先回到http://localhost:8080/DeploySYS根路径下
		 */


		//response.sendRedirect("../caizh/FILE/FileMain.jsp");
		//response.sendRedirect("../servlet/FileDeal");
		
		
		String mainGo=request.getParameter("mainGo");
		String mt=request.getParameter("mt");
		if("fileMain".equals(mainGo))
		{
			if("findRoots".equals(mt))
			{
				request.getRequestDispatcher("/servlet/FileDeal").forward(request, response);//转发请求至相应servlet进行处理
			}
		
		}
		
		}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
